from autoTest_BRTC_API.core.userApiUtils import userapiutil
from autoTest_BRTC_API.utils.readFile import read_yaml
from autoTest_BRTC_API.utils.writeFile import write_yaml

headers = read_yaml('common.yaml')['headers']
class UserAPI():
    def reg_api(self,req,params):
        ### 发送请求，并接收接口返回的数据
        res = userapiutil.reg_util(req,headers=headers,json=params)
        return res
    def login_api(self,req,params):
        # 拼接URL
        res = userapiutil.login_util(req,headers=headers,json=params)
        # print(res.json())
        # 当接口成功登录在返回
        if "data" in res.json():
            # 将userId和token获取到yaml
            # 获取UserId
            userId = res.json()['data']['userId']
            # 获取token
            token = res.json()['data']['token']
            content = {
                'userId': userId,
                'token': token
            }
            print(userId,token)
            write_yaml('temp.yaml',content)
        return res
    def modfiyUserNick_api(self,req,params):
        data=read_yaml('temp.yaml')
        headers2={
            "userId":str(data['userId']),
            "token":data['token']
        }

        # 拼接URL
        res = userapiutil.modfiyUserNick_util(req, headers=headers2, data=params)
        return res





## 实例化UserAPI对象
userapi = UserAPI()

# if __name__ == "__main__":
#     userapi.login_api()

